//
//  UIButton-Extension.swift
//  XLWB
//
//  Created by 郭亮 on 16/3/13.
//  Copyright © 2016年 gl. All rights reserved.
//

import UIKit

extension UIButton {
    //便利方法
    convenience init(imageName: String, backImageName: String) {
        self.init()//遍历方法必须调用
        setImage(UIImage(named: imageName), forState: .Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        sizeToFit()
    }
    
    convenience init(title: String, bgColor: UIColor, fontsize: CGFloat) {
        self.init()
        setTitle(title, forState: .Normal)
        backgroundColor = bgColor
        titleLabel?.font = UIFont.systemFontOfSize(fontsize)
    }
    
    //类方法
    class func creatButton(imageName: String, backImageName: String) -> UIButton {
        let btn = UIButton(type: .Custom)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        btn.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        btn.sizeToFit()
        return btn
    }
    
}